TKey
TValue
CSharpTest.Net
KeyValueComparer<TKey,TValue> Class
Members  Example  See Also  Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace : KeyValueComparer<TKey,TValue> Class

Glossary Item Box

Represents a key-value comparison

Syntax

Visual Basic (Declaration) 
Public Class KeyValueComparer
    (Of TKey,TValue) 
C# 
public class KeyValueComparer<TKey,TValue> 

Type Parameters

TKey
TValue

Example

Library/Library.Test/TestOrderedEnumeration.cs

C#Copy Code
KeyValueComparer<int, int> cmp = new KeyValueComparer<int, int>();
Assert.IsTrue(ReferenceEquals(Comparer<int>.Default, cmp.Comparer));
Assert.IsTrue(ReferenceEquals(Comparer<int>.Default, KeyValueComparer<int, int>.Default.Comparer));

Assert.AreEqual(-1, cmp.Compare(new KeyValuePair<int, int>(1, 1), new KeyValuePair<int, int>(2, 1)));
Assert.AreEqual(0, cmp.Compare(new KeyValuePair<int, int>(1, 1), new KeyValuePair<int, int>(1, 2)));
Assert.AreEqual(1, cmp.Compare(new KeyValuePair<int, int>(2, 1), new KeyValuePair<int, int>(1, 1)));
VB.NETCopy Code
Dim cmp As New KeyValueComparer(Of Integer, Integer)()
Assert.IsTrue(ReferenceEquals(Comparer(Of Integer).[Default], cmp.Comparer))
Assert.IsTrue(ReferenceEquals(Comparer(Of Integer).[Default], KeyValueComparer(Of Integer, Integer).[Default].Comparer))

Assert.AreEqual(-1, cmp.Compare(New KeyValuePair(Of Integer, Integer)(1, 1), New KeyValuePair(Of Integer, Integer)(2, 1)))
Assert.AreEqual(0, cmp.Compare(New KeyValuePair(Of Integer, Integer)(1, 1), New KeyValuePair(Of Integer, Integer)(1, 2)))
Assert.AreEqual(1, cmp.Compare(New KeyValuePair(Of Integer, Integer)(2, 1), New KeyValuePair(Of Integer, Integer)(1, 1)))

Inheritance Hierarchy

System.Object
   CSharpTest.Net.Collections.KeyValueComparer<TKey,TValue>

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys